package servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import service.Servicet;
import vo.Books;

@WebServlet("/Repay")
public class RepayServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Servicet s = new Servicet();
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		request.setCharacterEncoding("utf-8");
//		String name = request.getParameter("name");
//		String sm = request.getParameter("text");
//		if("".equals(name) || "".equals(sm)) {
//			request.getRequestDispatcher("aaa/Dome2.jsp").forward(request, response);
//		}else {
//			request.getRequestDispatcher("aaa/Dome1.jsp").forward(request, response);
//			s.delete(name, sm);
//		}
		
		request.setCharacterEncoding("utf-8");
		String name = request.getParameter("name");
		List<Books> list = new ArrayList<Books>();
		list.clear();
		list = s.fun(name);
		HttpSession session = request.getSession();
		session.setAttribute("name1", name);
		if(list.size() != 0) {
			session.setAttribute("book", list);
			response.sendRedirect("aaa/Dome2.jsp");
		}else {
			session.setAttribute("book", list);
			response.sendRedirect("aaa/Dome1.jsp");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
